A computer program is typically written in a high-level programming language. This high-level program, or source code, is then compiled by a compiler into object code. The object code is further processed and eventually turned into an executable program.
When compiling the source code, it is important that the compiler generate object code that optimizes use of computer resources. Often, it is necessary to examine the execution of the compiled program to determine when and where optimization is required. A "profiler" is a software tool that examines the execution of a program. By examining a profiler's output, a programmer can learn which regions of the profiled program will benefit from additional optimization.
Generally speaking, techniques used by current software-based profilers can be divided into two camps: sampling and instrumenting. In sampling, the profiled program is periodically halted and its state is then examined. Given enough samples, sampling can obtain a relatively good representation of the program's behavior.
In instrumenting, code is added to the profiled program. When the program is executed, the instrumentation code gathers statistics about the program's behavior. Since the instrumentation code is present and operating during the entire execution of the program, instrumenting can produce extremely detailed profile information.
Both of these techniques, however, suffer significant drawbacks. Sampling only provides states of the program at particular instants in time. Sampling provides only little, if any, information about how the program reached each particular state. Instrumenting, on the other hand, provides detailed information about the state of the program, but is extremely computationally expensive. That is, an instrumented application executes very slowly.
Therefore, there is a need in the art for a profiler that provides detailed information at a low cost.
That is, there is a need in the art for a profiling technique that produces the detailed information available through instrumenting while executing at the speed associated with sampling.